import Styles from './index.module.less';
import NavBar from '../../component/navbar/index';
import {useEffect,useState} from 'react'
import Taro from '@tarojs/taro'
import {Request, getGlobalData} from '../../util';
export default function index () {

    const navBarHeight = Taro.getStorageSync("navBarHeight");
    const domain = getGlobalData(domain);
    const name = Taro.getStorageSync("selectedTreatment");
    const [treatmentInfo,setTreatmentInfo] = useState({
        mins:0,
        poster_url:"",
        old_price: 0,
        new_price: 0
    });

    const getTreatment = () => {
        Request(domain+"/client/treatment/treatmentForDetailPage",{name:name}).then((res)=>{
            const info = res.data.data;
   
            setTreatmentInfo({
                mins: info.mins,
                new_price: info.new_price,
                old_price: info.old_price,
                poster_url: info.poster_url
            })
        });
    }

    useEffect(()=>{
        getTreatment()
    },[])

    const handleBookBtn = () => {
        Taro.switchTab({
            url: '/pages/book/index',
        })
    }

    return (
        <view>
            <NavBar title="疗程介绍" backTo="prev"/>
            <view class={Styles.topBar} style={{marginTop:navBarHeight}}>
                <view class={Styles.leftInfo}>
                    <view class={Styles.headline}>{name}</view>
                    <view class={Styles.mins}>时长：{treatmentInfo.mins}分钟</view>
                </view>
                <view class={Styles.rightInfo}>
                    <view class={Styles.newPrice}>
                        <view class={Styles.CNY}>￥</view> 
                        <view class={Styles.price}>{treatmentInfo.new_price}</view>
                    </view>
                    <view class={Styles.oldPrice}>￥{treatmentInfo.old_price}</view>
                </view>
            </view>
            <image src={treatmentInfo.poster_url} class={Styles.landingPage} mode="widthFix"/>

            <view class={Styles.bookWrap}>
                    <view class={Styles.book} onClick={()=>{
                        handleBookBtn()
                    }}>立即预约</view>
            </view>
        </view>
    )
}